package com.tqffram.hibernate.controller;

import com.tqffram.hibernate.entitry.Person;
import com.tqffram.hibernate.service.PersonService;
import com.tqffram.hibernate.service.impl.PersonServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 唐祺峰
 * @Date: 2022/2/15 0015 17:02
 * @Version 1.0
 */
@RestController
public class PersonController {

    @Autowired
    private PersonServiceImpl personService;

    /**
     * http://localhost:9099/hibernate/findById/1
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    public String findById(@PathVariable(name = "id") String id){
        return personService.findById(Long.parseLong(id)).toString();
    }
    /**
     * http://localhost:9099/hibernate/findByName/张三
     * @return
     */
    @GetMapping("/findByName/{name}")
    public String findByName(@PathVariable(name = "name") String name){
        return personService.findByName(name).toString();
    }

    /**
     *http://localhost:9099/hibernate/save
     * @return
     */
    @GetMapping("/save")
    public String save(){
        Person person = new Person();
        person.setName("张三");
        personService.save(person);
        return "插入成功";
    }



}
